package com.qian.ddj.web.controller;

import com.qian.api.ddj.model.DfBusiness;
import com.qian.api.ddj.model.StatusDict;
import com.qian.api.ddj.model.User;
import com.qian.api.ddj.service.IDfBusinessService;
import com.qian.api.ddj.service.IUserService;
import com.yaowk.api.common.PageReq;
import com.yaowk.api.common.PageResp;
import com.yaowk.web.system.security.SecurityUtils;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/ddj/dfBusiness")
@Api(tags = "代付商户管理")
public class DfBusinessController {

    @Autowired
    private IDfBusinessService businessService;
    @Autowired
    private IUserService userService;

    @PostMapping("/save")
    public void save(DfBusiness dfBusiness){
        businessService.save(dfBusiness);
    }

    @GetMapping("/{id}")
    public DfBusiness findById(@PathVariable Integer id){
        return businessService.findById(id);
    }

    @GetMapping("/all")
    public PageResp<DfBusiness> findAll(PageReq pageReq){
        PageResp<DfBusiness> pageResp = businessService.findAll(pageReq);
        return pageResp;
    }

    @GetMapping("/delete/{id}")
    public void deleteById(@PathVariable Integer id){
        businessService.deleteById(id);
    }

    @GetMapping("/allow")
    public PageResp<DfBusiness> findByStatus(PageReq pageReq){
        DfBusiness dfBusiness = new DfBusiness();
        dfBusiness.setStatus(StatusDict.NORMAL);
        PageResp<DfBusiness> pageResp = businessService.findAll(dfBusiness,pageReq);
        return pageResp;
    }

    @GetMapping("/user/bank")
    public String bankCode(){
        User user = userService.findById(SecurityUtils.getUserId());
        DfBusiness dfBusiness = businessService.findById(user.getDfBusinessId());
        return dfBusiness.getBackup3();
    }
}
